<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .bos {
            width: 200px;
            height: 30px;
            background-color: pink;
        }

        a {
            color: black;
            line-height: 100%;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            width: 23%;
            height: 29px;
        }

        .line {
            width: 50px;
            height: 1px;
            position: relative;
            left: 0px;
            background-color: greenyellow;
            transition: all .3s;
        }

        .yi {
            width: 100px;
            height: 100px;
            background-color: skyblue;

        }
    </style>
</head>

<body>
    <div class="bos">
        <a href="#">首页</a>
        <a href="#">动画</a>
        <a href="#">番剧</a>
        <a href="#">国创</a>
        <div class="line"></div>
    </div>
    <div class="yi"></div>
    <script>
        //滑块移动
        // 设置事件委托
        // 获取点击盒子的left位置
        // 将盒子赋给line的left
        const bos = document.querySelector('.bos');
        const line = document.querySelector('.line');
        console.log(bos);
        bos.addEventListener('click', function (e) {
            if (e.target.tagName === 'A') {
                console.log(111);
                const wei = e.target.offsetLeft;
                console.log(`${wei}px`);
                line.style.left = `${wei}px`;
            }
        })
        const yi = document.querySelector('.yi');
        console.log(yi);
        yi.style.transform = `translateX(${100}px)`;

    </script>
</body>

</html>